package com.ycp.erp.analysis.ui.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.jakewharton.rxbinding2.view.RxView;
import com.one.common.config.RouterPath;
import com.one.common.utils.KeyboardUtil;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.widget.MyTitleBar;
import com.ycp.erp.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Class Des:统计
 * Created by bjh on 2021/9/18.
 */
@Route(path = RouterPath.STATISTICAL_ANALYSIS)
public class StatisticalAnalysisActivity extends BaseActivity {
    @BindView(R.id.tvDay)
    TextView tvDay;
    @BindView(R.id.tvWeek)
    TextView tvWeek;
    @BindView(R.id.tvMonth)
    TextView tvMonth;
    @BindView(R.id.tvFirstRange)
    TextView tvFirstRange;
    @BindView(R.id.tvSecondRange)
    TextView tvSecondRange;
    @BindView(R.id.tvThirdRange)
    TextView tvThirdRange;
    @BindView(R.id.llTop)
    LinearLayout llTop;
    @BindView(R.id.tvStartDate)
    TextView tvStartDate;
    @BindView(R.id.tvEndDate)
    TextView tvEndDate;

    @Override
    protected void initPresenter() {

    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_staistical_analysis;
    }

    @SuppressLint("CheckResult")
    @Override
    public void initView() {
        super.initView();
        tvDay.setOnClickListener(this);
        tvWeek.setOnClickListener(this);
        tvMonth.setOnClickListener(this);
        tvFirstRange.setOnClickListener(this);
        tvSecondRange.setOnClickListener(this);
        tvThirdRange.setOnClickListener(this);
        tvDay.setSelected(true);
        tvDay.setTextColor(getResources().getColor(R.color.root_blue));
        tvFirstRange.setSelected(true);
        tvFirstRange.setTextColor(getResources().getColor(R.color.root_blue));
        RxView.clicks(tvStartDate).throttleFirst(1, TimeUnit.SECONDS).subscribe(o -> {
            new KeyboardUtil(mContext).hideSoftInputFromWindow(myRxActivity);
            TimePickerView pvTime = new TimePickerBuilder(myRxActivity, new OnTimeSelectListener() {
                @Override
                public void onTimeSelect(Date date, View v) {
                    tvStartDate.setText( new SimpleDateFormat("yyyy-MM-dd").format(date));
                }
            })
                    .setSubmitColor(getResources().getColor(R.color.root_green))
                    .setCancelColor(getResources().getColor(R.color.gray_d6))
                    .setLineSpacingMultiplier(2.8f)
                    .build();
            pvTime.show();
        });
        RxView.clicks(tvEndDate).throttleFirst(1, TimeUnit.SECONDS).subscribe(o -> {
            new KeyboardUtil(mContext).hideSoftInputFromWindow(myRxActivity);
            TimePickerView pvTime = new TimePickerBuilder(myRxActivity, new OnTimeSelectListener() {
                @Override
                public void onTimeSelect(Date date, View v) {
                    tvEndDate.setText(new SimpleDateFormat("yyyy-MM-dd").format(date));
                }
            })
                    .setSubmitColor(getResources().getColor(R.color.root_green))
                    .setCancelColor(getResources().getColor(R.color.gray_d6))
                    .setLineSpacingMultiplier(2.8f)
                    .build();
            pvTime.show();
        });
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("统计分析").hideLine();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tvDay:
                tvDay.setSelected(true);
                tvWeek.setSelected(false);
                tvMonth.setSelected(false);
                tvDay.setTextColor(getResources().getColor(R.color.root_blue));
                tvWeek.setTextColor(getResources().getColor(R.color.color_d2));
                tvMonth.setTextColor(getResources().getColor(R.color.color_d2));
                break;
            case R.id.tvWeek:
                tvWeek.setSelected(true);
                tvDay.setSelected(false);
                tvMonth.setSelected(false);
                tvWeek.setTextColor(getResources().getColor(R.color.root_blue));
                tvDay.setTextColor(getResources().getColor(R.color.color_d2));
                tvMonth.setTextColor(getResources().getColor(R.color.color_d2));
                break;
            case R.id.tvMonth:
                tvMonth.setSelected(true);
                tvWeek.setSelected(false);
                tvDay.setSelected(false);
                tvMonth.setTextColor(getResources().getColor(R.color.root_blue));
                tvWeek.setTextColor(getResources().getColor(R.color.color_d2));
                tvDay.setTextColor(getResources().getColor(R.color.color_d2));
                break;
            case R.id.tvFirstRange:
                tvFirstRange.setSelected(true);
                tvSecondRange.setSelected(false);
                tvThirdRange.setSelected(false);
                tvFirstRange.setTextColor(getResources().getColor(R.color.root_blue));
                tvSecondRange.setTextColor(getResources().getColor(R.color.color_d2));
                tvThirdRange.setTextColor(getResources().getColor(R.color.color_d2));
                break;
            case R.id.tvSecondRange:
                tvSecondRange.setSelected(true);
                tvFirstRange.setSelected(false);
                tvThirdRange.setSelected(false);
                tvSecondRange.setTextColor(getResources().getColor(R.color.root_blue));
                tvFirstRange.setTextColor(getResources().getColor(R.color.color_d2));
                tvThirdRange.setTextColor(getResources().getColor(R.color.color_d2));
                break;
            case R.id.tvThirdRange:
                tvThirdRange.setSelected(true);
                tvFirstRange.setSelected(false);
                tvSecondRange.setSelected(false);
                tvThirdRange.setTextColor(getResources().getColor(R.color.root_blue));
                tvFirstRange.setTextColor(getResources().getColor(R.color.color_d2));
                tvSecondRange.setTextColor(getResources().getColor(R.color.color_d2));
                break;
            default:
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
